package com.lumyc.openfeignclient.controller;

import com.lumyc.openfeignclient.feignclient.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName UserController
 * @Description TODO
 * @Author lumyc
 * @Date 2022/11/16 13:51
 * @Version 1.0
 */
@RestController
@RequestMapping("/consumer")
public class UserController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private UserFeign userFeign;

    @GetMapping("/get/by/rest/{id}")
    public String getRemote(@PathVariable String id){

        return restTemplate.getForObject("http://openfeign-server/user/get/by/" + id, String.class);

    }

    @GetMapping("/get/by/feign/{id}")
    public String getRemote2(@PathVariable String id){

        return userFeign.getById(id);
    }

}
